package com.heima.leetcode.practice;

import java.util.LinkedList;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: leetcode 225. 用队列实现栈
 * @date 2025/3/4 20:05
 */
public class E225 {
    public static class MyStack {

        private final LinkedList<Integer> queue;

        public MyStack() {
            queue = new LinkedList<>();
        }

        public void push(int x) {
            queue.offer(x);
            for (int i = 0; i < queue.size() - 1; i++)
                queue.offer(queue.poll());
        }

        @SuppressWarnings("all")
        public int pop() {
            return queue.poll();
        }

        @SuppressWarnings("all")
        public int top() {
            return queue.peek();
        }

        public boolean empty() {
            return queue.isEmpty();
        }
    }
}
